#include "stdafx.h"

#include "InputState.h"

namespace ETM
{
	namespace Input
	{
		bool keysCurrent[sf::Key::Count];
		bool keysPrevious[sf::Key::Count];

		void SetCurrentState(const sf::Input& input)
		{
			for(int i = 0; i < sf::Key::Count; i++)
			{
				keysCurrent[i] = input.IsKeyDown((sf::Key::Code)i);
			}
		}

		void SetPreviousState(const sf::Input& input)
		{
			for(int i = 0; i < sf::Key::Count; i++)
			{
				keysPrevious[i] = input.IsKeyDown((sf::Key::Code)i);
			}
		}

		bool IsKeyDown(sf::Key::Code keyCode)
		{
			return keysCurrent[keyCode];
		}

		bool IsKeyFirstDown(sf::Key::Code keyCode)
		{
			return keysCurrent[keyCode] && !keysPrevious[keyCode];
		}

		bool IsKeyUp(sf::Key::Code keyCode)
		{
			return !keysCurrent[keyCode];
		}

		bool IsKeyFirstUp(sf::Key::Code keyCode)
		{
			return !keysCurrent[keyCode] && keysPrevious[keyCode];
		}

		bool IsMenuUp()
		{
			return IsKeyFirstDown(sf::Key::Up) || IsKeyFirstDown(sf::Key::W);
		}

		bool IsMenuDown()
		{
			return IsKeyFirstDown(sf::Key::Down) || IsKeyFirstDown(sf::Key::S);
		}

		bool IsMenuBack()
		{
			return IsKeyFirstDown(sf::Key::Escape);
		}

		bool IsMenuSelect()
		{
			return IsKeyFirstDown(sf::Key::Space) || IsKeyFirstDown(sf::Key::Return);
		}
	}
}